#!/usr/bin/python
# coding: UTF-8 
#@author: rui.xu <mrhaigui@gmail.com>
#Filename:
import web
import conf
import util
from web.contrib.template import render_jinja
urls = (
#		'/',index,
		'/login',login
		)

render = conf.adminrender
app = web.application(urls, globals())
def set_login_cookie(usercheck):
	web.setcookie('userid',usercheck)
class index:
	def GET(self):
		c = web.cookies(usercheck=None)
		auth = util.if_login(c)
		if auth:
			return render.index("hello OK")

class login:
	def GET(self):
		web.header('Content-Type','text/html; charset=UTF-8')
		c = web.cookies(userid=None)
		auth = util.if_login(c)
		if auth:
			#raise web.seeother('/')
			return "OK"
		return render.login(locals())
	def POST(self):
		web.header('Content-Type','text/html; charset=UTF-8')
		i = web.input()
		LoginName = i.LoginName
		LoginPass = i.LoginPass
		checkcode = util.md5(LoginName+LoginPass)
		if checkcode == util.md5("daxuxu"+"kiss me"):
			set_login_cookie(checkcode)
			return render.index(code="OK")
		else:
			return render.index(code="not OK")





if __name__ == '__main__':
	app.run()



